function shallowCopy(obj) {
	let newObj = Array.isArray(obj) ? [] : {};
	for (let key in obj) {
		// 避免拷贝原型上的数据
		if (obj.hasOwnProperty(key)) {
			newObj[key] = obj[key];
		}
	}
	return newObj;
}
let person = {
	name: "张三",
	hobby: ["篮球", "排球"],
};
let arr = [1, 2, 3, 4, [2, 3, 4, 5]];
let arr1 = shallowCopy(arr);
arr1[1] = 0;
console.log(arr);
console.log(arr1);

let person1 = shallowCopy(person);
person1.hobby[1] = "羽毛球";
person1.name = "李四";
console.log(person.hobby); // [ '篮球', '羽毛球' ]
console.log(person1.hobby); // [ '篮球', '羽毛球' ]

console.log(person.name); // 张三
console.log(person1.name); // 李四
